package com.neusoft.elm.controller;

import com.neusoft.elm.po.User;
import com.neusoft.elm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/UserController")
@CrossOrigin
public class UserController {

    @Autowired
    private UserService userService;
@PostMapping("/saveUser")
public Object saveUser(String userId, String password,String userName,int userSex) {
    try {
        User user = new User(userId,password,userName,userSex,null);

        int i = userService.saveUser(user);
        return i;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

}
@RequestMapping("/getUserById")
public Object getUserById(String userId) {

    try {
        User user=userService.getUserById(userId);
        return user;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

}
@RequestMapping("/getUserByIdByPass")
    public Object getUserByIdByPass(String userId,String password) {
        try {
            User user=userService.getUserByIdByPass(userId,password);
            return user;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

    }

}
